<?php
class News_Service_Search {
	private $_modelName;
	
	private $_view = null;
	
	public function __construct() {
		$this->_modelName = "News_Model_News";
		if($this->_view === null) {
			$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
			if (null === $viewRenderer->view) {
				$viewRenderer->initView();
			}
			$view = $viewRenderer->view;
			$this->_view = $view;
		}
	}
	
	public function getwords() {
		$news = Doctrine_Query::create()
				->from($this->_modelName)
				->where('published = ?', true)
				->execute();
		$words = array();
		
		$locales = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOption('locales');
		foreach($locales as $lang=>$value) {
			foreach ($news as $key=>$item) {
				$words["news"]['words'][$lang][$key]['id'] = $item->id;
				$words["news"]['words'][$lang][$key]['uri'] = $this->_view->url(array('id' => $item->id),'news_index_show');
				$words["news"]['words'][$lang][$key]['name'] = $item->Translation[$lang]->name;
				$words["news"]['words'][$lang][$key]['anonce'] = $item->Translation[$lang]->anonce;
				$words["news"]['words'][$lang][$key]['content'] = $item->Translation[$lang]->content;
			}
		}
		
		return $words;
	}
}